package com.liuceng.mps.web.controller;

import com.liuceng.mps.service.SocketIoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by song_yu on 2017/3/20.
 */
@Controller
public class SocketIoController {
    @Autowired
    private SocketIoService service;

    /**
     * 分配客资
     * @param request
     * @param response
     * @throws Exception
     */
    @RequestMapping("/dashboard/assign_request")
    public void assignCustomer(String adminid, String customerid, String clickurl, String message, HttpServletRequest request, HttpServletResponse response) throws Exception{
        try {
            Map<String, String> data = new HashMap<>();
            data.put("adminid", adminid);
            data.put("customerid", customerid);
            data.put("clickurl", clickurl);
            data.put("message", message);
            service.assignCustomer(adminid, "assign_push", data);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 下一待接收网销提示
     * @param request
     * @param response
     * @throws Exception
     */
    @RequestMapping("/dashboard/send_push_tips ")
    public void remindAll(String message,String adminIds,HttpServletRequest request, HttpServletResponse response) throws Exception{
        try {
            service.remindAll(adminIds, "push_tips", message);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/stopServer")
    public void stopServer(HttpServletRequest request,HttpServletResponse response) throws Exception {
        try {
            if(service.getServer() != null) {
                service.startServer();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
